
package com.qianxx.base.uploadFile;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.Serializable;

public class FormFile implements Serializable
{
	/**
	 * 
	 */
	private static final long	serialVersionUID	= 2720829343057833312L;
	/* 上传文件的数据 */
	private byte[]		data;
	private InputStream	inStream;
	private File		file;
	/* 文件描述 */
	private FileDesc	fileDesc;
	/* 文件大小 */
	private int			fileSize;
	/* 文件名称 */
	private String		filname;
	/* 请求参数名称 */
	private String		parameterName;
	/* 内容类型 */
	private String		contentType	= "application/octet-stream";
	
	public FormFile ( )
	{
	}
	
	/**
	 * 构造函数初始化FormFile类的参数
	 * @param filname
	 * 文件名 不包含路径
	 * @param file
	 * File类型文件对象
	 * @param parameterName
	 * 文件上传时的key
	 * @param contentType
	 * 文件类型，用于上传时使用，如果没有特殊要求,传空值时，默认application/octet-stream;
	 * @param fileDesc
	 * */
	public FormFile ( String filname, File file, String parameterName, String contentType, FileDesc fileDesc )
	{
		this.filname = filname;
		this.parameterName = parameterName;
		this.file = file;
		try
		{
			this.inStream = new FileInputStream ( file );
		} catch ( FileNotFoundException e )
		{
			e.printStackTrace ( );
		}
		if ( contentType != null ) this.contentType = contentType;
		if ( fileDesc != null ) this.fileDesc = fileDesc;
	}
	
	// public FormFile ( String filname, byte[] data, String parameterName, String contentType , String fileDesc )
	// {
	// this.data = data;
	// this.filname = filname;
	// this.parameterName = parameterName;
	// if ( contentType != null ) this.contentType = contentType;
	// if ( fileDesc != null ) this.fileDesc = fileDesc;
	// }
	// public FormFile ( InputStream inStream, int fileSize, String filname, String parameterName, String contentType,
	// String fileDesc )
	// {
	// super ( );
	// this.inStream = inStream;
	// this.fileSize = fileSize;
	// this.filname = filname;
	// this.parameterName = parameterName;
	// if ( contentType != null ) this.contentType = contentType;
	// if ( fileDesc != null ) this.fileDesc = fileDesc;
	// }
	public int getFileSize ( )
	{
		return fileSize;
	}
	
	public File getFile ( )
	{
		return file;
	}
	
	public InputStream getInStream ( )
	{
		return inStream;
	}
	
	public byte[] getData ( )
	{
		return data;
	}
	
	public String getFilname ( )
	{
		return filname;
	}
	
	public void setFilname ( String filname )
	{
		this.filname = filname;
	}
	
	public String getParameterName ( )
	{
		return parameterName;
	}
	
	public void setParameterName ( String parameterName )
	{
		this.parameterName = parameterName;
	}
	
	public String getContentType ( )
	{
		return contentType;
	}
	
	public void setContentType ( String contentType )
	{
		this.contentType = contentType;
	}
	
	public FileDesc getFileDesc ( )
	{
		return fileDesc;
	}
	
	public void setFileDesc ( FileDesc fileDesc )
	{
		this.fileDesc = fileDesc;
	}
}
